/*
 * NuevoEmpleado.java
 *
 * Created on 28 de septiembre de 2008, 18:46
 */
package podologia;

import controller.GestorEmpleado;
import java.awt.Color;
import java.text.DecimalFormat;
import javax.persistence.EntityTransaction;
import javax.swing.JOptionPane;
import javax.swing.text.JTextComponent;
import podologia.beansDB.Barrio;
import podologia.beansDB.Direccion;
import podologia.beansDB.Empleado;
import podologia.beansDB.Localidad;
import podologia.beansDB.Pais;
import podologia.beansDB.Persona;
import podologia.beansDB.Practica;
import podologia.beansDB.Practicaxempleado;
import podologia.beansDB.Provincia;
import podologia.beansDB.Tipodoc;
import podologia.exceptions.BusinessException;
import podologia.util.ValidadorNumerico;

/**
 *
 * @author  Hernan
 */
public class NuevoEmpleado extends javax.swing.JInternalFrame {

    private Empleado empleadoOpen = new Empleado();
    private Boolean update = false;

    /** Creates new form NuevoEmpleado */
    public NuevoEmpleado() {
        initComponents();
        editable(true);
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        PodologiaPUEntityManager.persist(empleadoOpen);
        practicaxempleadoList.clear();
        tx.commit();
        jButton2.setVisible(false);

    }

    public NuevoEmpleado(Empleado e) {
        empleadoOpen = e;
        initComponents();
        editable(false);
        update = true;
        cargar();
        this.setTitle("Editar Empleado " + e.getIdPersona().getApellido() + ", " + e.getIdPersona().getNombre());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        PodologiaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("PodologiaPU").createEntityManager();
        tipodocQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT t FROM Tipodoc t");
        tipodocList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : tipodocQuery.getResultList();
        practicaQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT p FROM Practica p");
        practicaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : practicaQuery.getResultList();
        practicaxempleadoQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT p FROM Practicaxempleado p");
        practicaxempleadoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : practicaxempleadoQuery.getResultList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldApe = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldNom = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxTipoDoc = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNumDoc = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldFechaNac = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldNac = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldEstadoC = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldTel = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldTelCelu = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldDireCalle = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jTextFieldDireBarrio = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldDireProvincia = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldDirePais = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldDireNum = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldDirePiso = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldDireDepto = new javax.swing.JTextField();
        jTextFieldDireLoc = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldLegajo = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jTextFieldemail = new javax.swing.JTextField();
        jTextFieldPass = new javax.swing.JTextField();
        jTextFieldUsuarioSist = new javax.swing.JTextField();
        jTextFieldFechaBaja = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaMotivoBaja = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        jTextFieldMatricula = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jComboBoxPractica = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTablePracticas = new javax.swing.JTable();
        jLabel27 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(podologia.PodologiaApp.class).getContext().getResourceMap(NuevoEmpleado.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldApe.setText(resourceMap.getString("jTextFieldApe.text")); // NOI18N
        jTextFieldApe.setName("jTextFieldApe"); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldNom.setName("jTextFieldNom"); // NOI18N

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jComboBoxTipoDoc.setName("jComboBoxTipoDoc"); // NOI18N

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipodocList, jComboBoxTipoDoc);
        bindingGroup.addBinding(jComboBoxBinding);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldNumDoc.setText(resourceMap.getString("jTextFieldNumDoc.text")); // NOI18N
        jTextFieldNumDoc.setName("jTextFieldNumDoc"); // NOI18N

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jTextFieldFechaNac.setText(resourceMap.getString("jTextFieldFechaNac.text")); // NOI18N
        jTextFieldFechaNac.setName("jTextFieldFechaNac"); // NOI18N

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jTextFieldNac.setText(resourceMap.getString("jTextFieldNac.text")); // NOI18N
        jTextFieldNac.setName("jTextFieldNac"); // NOI18N

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldEstadoC.setText(resourceMap.getString("jTextFieldEstadoC.text")); // NOI18N
        jTextFieldEstadoC.setName("jTextFieldEstadoC"); // NOI18N

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTextFieldTel.setText(resourceMap.getString("jTextFieldTel.text")); // NOI18N
        jTextFieldTel.setName("jTextFieldTel"); // NOI18N

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTextFieldTelCelu.setText(resourceMap.getString("jTextFieldTelCelu.text")); // NOI18N
        jTextFieldTelCelu.setName("jTextFieldTelCelu"); // NOI18N

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jTextFieldDireCalle.setText(resourceMap.getString("jTextFieldDireCalle.text")); // NOI18N
        jTextFieldDireCalle.setName("jTextFieldDireCalle"); // NOI18N

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jTextFieldDireBarrio.setText(resourceMap.getString("jTextFieldDireBarrio.text")); // NOI18N
        jTextFieldDireBarrio.setName("jTextFieldDireBarrio"); // NOI18N

        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jTextFieldDireProvincia.setText(resourceMap.getString("jTextFieldDireProvincia.text")); // NOI18N
        jTextFieldDireProvincia.setName("jTextFieldDireProvincia"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jTextFieldDirePais.setText(resourceMap.getString("jTextFieldDirePais.text")); // NOI18N
        jTextFieldDirePais.setName("jTextFieldDirePais"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jTextFieldDireNum.setText(resourceMap.getString("jTextFieldDireNum.text")); // NOI18N
        jTextFieldDireNum.setName("jTextFieldDireNum"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jTextFieldDirePiso.setText(resourceMap.getString("jTextFieldDirePiso.text")); // NOI18N
        jTextFieldDirePiso.setName("jTextFieldDirePiso"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jTextFieldDireDepto.setText(resourceMap.getString("jTextFieldDireDepto.text")); // NOI18N
        jTextFieldDireDepto.setName("jTextFieldDireDepto"); // NOI18N

        jTextFieldDireLoc.setText(resourceMap.getString("jTextFieldDireLoc.text")); // NOI18N
        jTextFieldDireLoc.setName("jTextFieldDireLoc"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jTextFieldLegajo.setBackground(resourceMap.getColor("jTextFieldLegajo.background")); // NOI18N
        jTextFieldLegajo.setEditable(false);
        jTextFieldLegajo.setText(resourceMap.getString("jTextFieldLegajo.text")); // NOI18N
        jTextFieldLegajo.setName("jTextFieldLegajo"); // NOI18N

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel23.setText(resourceMap.getString("jLabel23.text")); // NOI18N
        jLabel23.setName("jLabel23"); // NOI18N

        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel24.setText(resourceMap.getString("jLabel24.text")); // NOI18N
        jLabel24.setName("jLabel24"); // NOI18N

        jTextFieldemail.setText(resourceMap.getString("jTextFieldemail.text")); // NOI18N
        jTextFieldemail.setName("jTextFieldemail"); // NOI18N

        jTextFieldPass.setText(resourceMap.getString("jTextFieldPass.text")); // NOI18N
        jTextFieldPass.setName("jTextFieldPass"); // NOI18N

        jTextFieldUsuarioSist.setText(resourceMap.getString("jTextFieldUsuarioSist.text")); // NOI18N
        jTextFieldUsuarioSist.setName("jTextFieldUsuarioSist"); // NOI18N

        jTextFieldFechaBaja.setText(resourceMap.getString("jTextFieldFechaBaja.text")); // NOI18N
        jTextFieldFechaBaja.setName("jTextFieldFechaBaja"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextAreaMotivoBaja.setColumns(20);
        jTextAreaMotivoBaja.setRows(5);
        jTextAreaMotivoBaja.setName("jTextAreaMotivoBaja"); // NOI18N
        jScrollPane1.setViewportView(jTextAreaMotivoBaja);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel25.setText(resourceMap.getString("jLabel25.text")); // NOI18N
        jLabel25.setName("jLabel25"); // NOI18N

        jTextFieldMatricula.setName("jTextFieldMatricula"); // NOI18N

        jLabel26.setText(resourceMap.getString("jLabel26.text")); // NOI18N
        jLabel26.setName("jLabel26"); // NOI18N

        jComboBoxPractica.setName("jComboBoxPractica"); // NOI18N

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, practicaList, jComboBoxPractica);
        bindingGroup.addBinding(jComboBoxBinding);

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setMinimumSize(new java.awt.Dimension(73, 20));
        jButton4.setName("jButton4"); // NOI18N
        jButton4.setPreferredSize(new java.awt.Dimension(73, 18));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.setPreferredSize(new java.awt.Dimension(73, 18));
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTablePracticas.setName("jTablePracticas"); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, practicaxempleadoList, jTablePracticas);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${practica.nombre}"));
        columnBinding.setColumnName("Practica.nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${matricula}"));
        columnBinding.setColumnName("Matricula");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(jTablePracticas);
        jTablePracticas.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTablePracticas.columnModel.title0")); // NOI18N
        jTablePracticas.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTablePracticas.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel25)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldMatricula, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxPractica, 0, 164, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(jComboBoxPractica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(jTextFieldMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel27.setText(resourceMap.getString("jLabel27.text")); // NOI18N
        jLabel27.setName("jLabel27"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldApe))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldNom, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldTelCelu))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldTel))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldEstadoC))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldNac))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldFechaNac))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jComboBoxTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel4)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldNumDoc)
                                    .addComponent(jLabel27)))
                            .addComponent(jLabel10)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDireCalle))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldDireBarrio, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldDireProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldDirePais)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                            .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                            .addComponent(jLabel21, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                            .addComponent(jLabel22, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                            .addComponent(jLabel23, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                            .addComponent(jLabel24, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldemail)
                            .addComponent(jTextFieldPass)
                            .addComponent(jTextFieldUsuarioSist)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldLegajo)
                                .addGap(137, 137, 137))
                            .addComponent(jScrollPane1)
                            .addComponent(jTextFieldFechaBaja, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(8, 8, 8)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTextFieldDireLoc)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel13)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel14)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel15, jLabel17, jLabel19, jLabel2, jLabel20, jLabel21, jLabel22, jLabel3, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldDireProvincia, jTextFieldFechaBaja, jTextFieldLegajo});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldApe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNumDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel27))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldEstadoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldTelCelu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldDireCalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldDireBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldDireLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18)
                            .addComponent(jTextFieldDireProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldDirePais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(jTextFieldLegajo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(jTextFieldUsuarioSist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel22))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(jTextFieldFechaBaja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel24)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton1))
                .addGap(5, 5, 5))
        );

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents

    private void guardar() {
        //Datos Persona
        Persona persona = new Persona();
        Direccion dire = new Direccion();
        Barrio barrio = new Barrio();
        Localidad loca = new Localidad();
        Provincia prov = new Provincia();
        Pais pais = new Pais();
        prov.setIdPais(pais);
        loca.setIdProvincia(prov);
        barrio.setIdLocalidad(loca);
        dire.setIdBarrio(barrio);
        persona.setIdDireccion(dire);
        empleadoOpen.setIdPersona(persona);
        empleadoOpen.getIdPersona().setApellido(jTextFieldApe.getText());
        empleadoOpen.getIdPersona().setNombre(jTextFieldNom.getText());
        empleadoOpen.getIdPersona().setIdTipoDoc((Tipodoc) jComboBoxTipoDoc.getSelectedItem());

        try {
            Double nroDoc = (Double) ValidadorNumerico.Validar(jTextFieldNumDoc, Double.class);
            empleadoOpen.getIdPersona().setNroDoc(nroDoc);
        } catch (NumberFormatException ex) {
            throw new BusinessException("El Documento debe contener solo numeros");
        }

        try {
            Integer TelPar = (Integer) ValidadorNumerico.Validar(jTextFieldTel, Integer.class);
            empleadoOpen.getIdPersona().setTelParticular(TelPar);
        } catch (NumberFormatException ex) {
            throw new BusinessException("El Telefono Particular debe contener solo numeros");
        }

        try {
            Integer TelMov = (Integer) ValidadorNumerico.Validar(jTextFieldTelCelu, Integer.class);
            empleadoOpen.getIdPersona().setTelMovil(TelMov);
        } catch (NumberFormatException ex) {
            throw new BusinessException("El Telefono Movil debe contener solo numeros");
        }

        empleadoOpen.getIdPersona().setFechaNacimiento(jTextFieldFechaNac.getText());
        empleadoOpen.getIdPersona().setNacionalidad(jTextFieldNac.getText());
        empleadoOpen.getIdPersona().setEstadoCivil(jTextFieldEstadoC.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setCalle(jTextFieldDireCalle.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setNumero(jTextFieldDireNum.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setPiso(jTextFieldDirePiso.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setDepto(jTextFieldDireDepto.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().setNombre(jTextFieldDireBarrio.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().setNombre(jTextFieldDireLoc.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().setNombre(jTextFieldDireProvincia.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().setNombre(jTextFieldDirePais.getText());

        //Datos Empleado
        empleadoOpen.setUsuario(jTextFieldUsuarioSist.getText());
        empleadoOpen.setPass(jTextFieldPass.getText());
        empleadoOpen.setMail(jTextFieldemail.getText());
        empleadoOpen.setFechaBaja(jTextFieldFechaBaja.getText());
        empleadoOpen.setMotivoBaja(jTextAreaMotivoBaja.getText());

        //Persistencia del Objeto
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        try {
            tx.begin();
            PodologiaPUEntityManager.merge(empleadoOpen);
            tx.commit();
            JOptionPane.showMessageDialog(this, "Empleado Guardado");
            dispose();
        } catch (RuntimeException ex) {
            tx.rollback();
            JOptionPane.showMessageDialog(this, "Error al Guardar el Empleado");
        }

    }

    private void update() {
        //Datos Persona
        empleadoOpen.getIdPersona().setApellido(jTextFieldApe.getText());
        empleadoOpen.getIdPersona().setNombre(jTextFieldNom.getText());
        empleadoOpen.getIdPersona().setIdTipoDoc((Tipodoc) jComboBoxTipoDoc.getSelectedItem());
        empleadoOpen.getIdPersona().setNroDoc(Double.parseDouble(jTextFieldNumDoc.getText()));
        empleadoOpen.getIdPersona().setTelParticular(Integer.parseInt(jTextFieldTel.getText()));
        empleadoOpen.getIdPersona().setTelMovil(Integer.parseInt(jTextFieldTelCelu.getText()));
        empleadoOpen.getIdPersona().setFechaNacimiento(jTextFieldFechaNac.getText());
        empleadoOpen.getIdPersona().setNacionalidad(jTextFieldNac.getText());
        empleadoOpen.getIdPersona().setEstadoCivil(jTextFieldEstadoC.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setCalle(jTextFieldDireCalle.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setNumero(jTextFieldDireNum.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setPiso(jTextFieldDirePiso.getText());
        empleadoOpen.getIdPersona().getIdDireccion().setDepto(jTextFieldDireDepto.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().setNombre(jTextFieldDireBarrio.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().setNombre(jTextFieldDireLoc.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().setNombre(jTextFieldDireProvincia.getText());
        empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().setNombre(jTextFieldDirePais.getText());
        //Datos Empleado
        empleadoOpen.setUsuario(jTextFieldUsuarioSist.getText());
        empleadoOpen.setPass(jTextFieldPass.getText());
        empleadoOpen.setMail(jTextFieldemail.getText());
        empleadoOpen.setFechaBaja(jTextFieldFechaBaja.getText());
        empleadoOpen.setMotivoBaja(jTextAreaMotivoBaja.getText());

        //Persistencia del Objeto
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        PodologiaPUEntityManager.merge(empleadoOpen);
        tx.commit();

    }

    private void cargar() {

        //Datos Persona
        DecimalFormat df = new DecimalFormat("0");
        jTextFieldApe.setText(empleadoOpen.getIdPersona().getApellido());
        jTextFieldNom.setText(empleadoOpen.getIdPersona().getNombre());
        jComboBoxTipoDoc.setSelectedItem(empleadoOpen.getIdPersona().getIdTipoDoc().getIdTipo());
        jTextFieldNumDoc.setText(df.format(empleadoOpen.getIdPersona().getNroDoc()));
        jTextFieldTel.setText(empleadoOpen.getIdPersona().getTelParticular().toString());
        jTextFieldTelCelu.setText(empleadoOpen.getIdPersona().getTelMovil().toString());
        jTextFieldFechaNac.setText(empleadoOpen.getIdPersona().getFechaNacimiento());
        jTextFieldNac.setText(empleadoOpen.getIdPersona().getNacionalidad());
        jTextFieldEstadoC.setText(empleadoOpen.getIdPersona().getEstadoCivil());
        jTextFieldDireCalle.setText(empleadoOpen.getIdPersona().getIdDireccion().getCalle());
        jTextFieldDireNum.setText(empleadoOpen.getIdPersona().getIdDireccion().getNumero());
        jTextFieldDirePiso.setText(empleadoOpen.getIdPersona().getIdDireccion().getPiso());
        jTextFieldDireDepto.setText(empleadoOpen.getIdPersona().getIdDireccion().getDepto());
        jTextFieldDireBarrio.setText(empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getNombre());
        jTextFieldDireLoc.setText(empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getNombre());
        jTextFieldDireProvincia.setText(empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getNombre());
        jTextFieldDirePais.setText(empleadoOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().getNombre());
        //Datos Empleado
        jTextFieldUsuarioSist.setText(empleadoOpen.getUsuario());
        jTextFieldPass.setText(empleadoOpen.getPass());
        jTextFieldemail.setText(empleadoOpen.getMail());
        jTextFieldFechaBaja.setText(empleadoOpen.getFechaBaja());
        jTextAreaMotivoBaja.setText(empleadoOpen.getMotivoBaja());

        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        practicaxempleadoQuery = PodologiaPUEntityManager.createQuery("SELECT pe FROM Practicaxempleado pe WHERE pe.empleado=:leg");
        practicaxempleadoQuery.setParameter("leg", empleadoOpen);
        practicaxempleadoList.clear();
        practicaxempleadoList.addAll(practicaxempleadoQuery.getResultList());
        jTablePracticas.updateUI();
        jTablePracticas.repaint();
        tx.commit();


    }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    if (!update) {
        if (JOptionPane.showConfirmDialog(this, "Esta seguro que desea cerrar sin guardar?", "Cerrar", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.YES_OPTION) {
            GestorEmpleado ge = new GestorEmpleado();
            ge.BorrarEmpleado(empleadoOpen, PodologiaPUEntityManager);
        }
    }
    PodologiaPUEntityManager.close();
    dispose();

}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    if (jButton2.getText().equals("Editar")) {
        editable(true);
        jButton2.setText("Cancelar");
    } else {
        if (jButton2.getText().equals("Cancelar")) {
            editable(false);
            jButton2.setText("Editar");

        }
    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    Practicaxempleado pe = new Practicaxempleado(((Practica) jComboBoxPractica.getSelectedItem()).getIdPractica(), empleadoOpen.getLegajo());
    pe.setEmpleado(empleadoOpen);
    pe.setPractica((Practica) jComboBoxPractica.getSelectedItem());
    pe.setMatricula(jTextFieldMatricula.getText());
    practicaxempleadoList.add(pe);
    jTablePracticas.updateUI();
    jTablePracticas.repaint();
    EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
    tx.begin();
    PodologiaPUEntityManager.persist(pe);
    tx.commit();

}//GEN-LAST:event_jButton4ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {
        validarDatos();
        if (update) {
            update();
        } else {
            guardar();
        }
    } catch (RuntimeException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage());
    }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    Practicaxempleado pe = practicaxempleadoList.get(jTablePracticas.getSelectedRow());
    EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
    tx.begin();
    PodologiaPUEntityManager.remove(pe);
    tx.commit();
    practicaxempleadoList.remove(pe);
    jTablePracticas.updateUI();
    jTablePracticas.repaint();

}//GEN-LAST:event_jButton5ActionPerformed

    private void editable(boolean flag) {
        if (flag) {
            for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
                if (this.jPanel1.getComponent(i) instanceof JTextComponent && !this.jPanel1.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(true);
                }
            }
            jTextAreaMotivoBaja.setEditable(true);
        } else {
            for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
                if (this.jPanel1.getComponent(i) instanceof JTextComponent && !this.jPanel1.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(false);
                }
            }
            jTextAreaMotivoBaja.setEditable(false);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager PodologiaPUEntityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBoxPractica;
    private javax.swing.JComboBox jComboBoxTipoDoc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTablePracticas;
    private javax.swing.JTextArea jTextAreaMotivoBaja;
    private javax.swing.JTextField jTextFieldApe;
    private javax.swing.JTextField jTextFieldDireBarrio;
    private javax.swing.JTextField jTextFieldDireCalle;
    private javax.swing.JTextField jTextFieldDireDepto;
    private javax.swing.JTextField jTextFieldDireLoc;
    private javax.swing.JTextField jTextFieldDireNum;
    private javax.swing.JTextField jTextFieldDirePais;
    private javax.swing.JTextField jTextFieldDirePiso;
    private javax.swing.JTextField jTextFieldDireProvincia;
    private javax.swing.JTextField jTextFieldEstadoC;
    private javax.swing.JTextField jTextFieldFechaBaja;
    private javax.swing.JTextField jTextFieldFechaNac;
    private javax.swing.JTextField jTextFieldLegajo;
    private javax.swing.JTextField jTextFieldMatricula;
    private javax.swing.JTextField jTextFieldNac;
    private javax.swing.JTextField jTextFieldNom;
    private javax.swing.JTextField jTextFieldNumDoc;
    private javax.swing.JTextField jTextFieldPass;
    private javax.swing.JTextField jTextFieldTel;
    private javax.swing.JTextField jTextFieldTelCelu;
    private javax.swing.JTextField jTextFieldUsuarioSist;
    private javax.swing.JTextField jTextFieldemail;
    private java.util.List<podologia.beansDB.Practica> practicaList;
    private javax.persistence.Query practicaQuery;
    private java.util.List<podologia.beansDB.Practicaxempleado> practicaxempleadoList;
    private javax.persistence.Query practicaxempleadoQuery;
    private java.util.List<podologia.beansDB.Tipodoc> tipodocList;
    private javax.persistence.Query tipodocQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void validarDatos() throws BusinessException {
        StringBuilder error = new StringBuilder();
        Boolean hayError = false;

        if (jTextFieldApe.getText().isEmpty()) {
            jTextFieldApe.setBackground(Color.RED);
            hayError = true;
            error.append("El Apellido no puede estar vacio \n");
        } else {
            jTextFieldApe.setBackground(Color.WHITE);
        }
        if (jTextFieldNom.getText().isEmpty()) {
            jTextFieldNom.setBackground(Color.RED);
            hayError = true;
            error.append("El Nombre no puede estar vacio \n");
        } else {
            jTextFieldNom.setBackground(Color.WHITE);
        }
        if (jTextFieldNumDoc.getText().isEmpty()) {
            jTextFieldNumDoc.setBackground(Color.RED);
            hayError = true;
            error.append("El Numero de Documento no puede estar vacio \n");
        } else {
            jTextFieldNumDoc.setBackground(Color.WHITE);
        }


        if (hayError) {
            throw new BusinessException(error.toString());
        }

    }
}
